package com.example.fengyungo.controller.user.user;

import com.example.fengyungo.constant.DriverConstant;
import com.example.fengyungo.constant.MailConstant;
import com.example.fengyungo.domain.pojo.Driver;
import com.example.fengyungo.result.Result;
import com.example.fengyungo.service.DriverService;
import com.example.fengyungo.service.MailService;
import com.example.fengyungo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/user")
public class UserVerifyController {

    @Autowired
    private MailService mailService;

    /**
     * 发送验证码到用户邮箱
     *
     * @param email 邮箱
     * @return 验证码
     */
    @GetMapping("/send/{email}")
    public Result<Boolean> sendEmailCode(@PathVariable String email) {
        Boolean send = mailService.sendCodeMailToUser(email);
        return Result.success(send);
    }

    /**
     * 对验证码进行验证
     *
     * @param email 邮箱
     * @param code  验证码
     * @return 验证结果
     */
    @GetMapping("/{email}/{code}")
    public Result<Boolean> verificationCode(@PathVariable String email, @PathVariable String code) {
        String identity = MailConstant.USER_IDENTITY;
        Boolean verification = mailService.verificationCode(identity, email, code);
        return Result.success(verification);
    }
}
